
#ifndef __HTTP_SERVER_H
#define __HTTP_SERVER_H

#include <apr.h>
#include "../aprtools/APRTable.h"
#include "TCPServer.h"

#define MAX_HEADERS 10

/** A HTTP server class, implemented over the top of the TCP
 * server. */
class HTTPServer : public TCPServer
{
   public:
      HTTPServer(int inoofthreads, int iportno, const char *ihostname, apr_pool_t *upperpool) :
         TCPServer(inoofthreads, iportno, ihostname, upperpool) {}
      ~HTTPServer() {}
      static APRTable *getTable(apr_pool_t *t_mp, apr_size_t clength, const char *separator, const char *eol, APRBucketBrigade *bb, APRMutex *waitinglock);
      APRTable *getHeaders(int i, apr_pool_t *t_mp);
      APRTable *getPOSTData(int i, apr_pool_t *t_mp, apr_size_t clength);
      static apr_off_t getContentLength(const APRTable *htable);
      int serveFilesFromWhiteList(const APRTable *htable, int i, apr_pool_t *t_mp, const char **fileswhitelist);
      void replyWithSentence(int i, apr_pool_t *t_mp, const char *body);
      void redirectAfterPOST(int i, apr_pool_t *t_mp, const char *relocation);
      void replyWithError404(int i);
      virtual void handleGETSession(int i, apr_pool_t *t_mp);
      virtual void handlePOSTSession(int i, apr_pool_t *t_mp);
      void handleClientsOnThread(int threadid, apr_pool_t *localmp);
      static void *handleClientsOnThreadStatic(apr_thread_t *tthread, void *args);
      /** Get the client handler as a function pointer. */
      virtual functor getClientHandlerFunction() const { return (functor)(&handleClientsOnThreadStatic); }
};

#endif
